import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            component: () => import('../views/Login.vue')
        },
        {
            path: '/login',
            redirect: '/'
        },
        {
            path: '/home',
            meta: { title: '首页' },
            component: () => import('../views/Home.vue'),
            children: [
                {
                    path: 'recommend',
                    meta: { title: '推荐' },
                    component: () => import('../views/Recommend.vue')
                },
                // {
                //     path: 'sub2',
                //     meta: { title: '子页面2' },
                //     component: () => import('../views/home/Sub2.vue')
                // }
            ]
        },
        {
            path: '/a',
            meta: { title: '视频' },
            component: () => import('../views/a.vue')
        },
        {
            path: '/discover',
            meta: { title: '发现音乐' },
            component: () => import('../views/Discover.vue'),
            children: [
                {
                    path: 'rankinglist',
                    meta: { title: '排行榜' },
                    component: () => import('../views/RankingList.vue')
                },
                {
                    path: 'songlist',
                    meta: { title: '歌单' },
                    component: () => import('../views/SongList.vue')
                },
                {
                    path: 'blog',
                    meta: { title: '博客' },
                    component: () => import('../views/Blog.vue')
                },
                {
                    path: 'singer',
                    meta: { title: '歌手' },
                    component: () => import('../views/Singer.vue')
                },
                {
                    path: 'newdiscpublish',
                    meta: { title: '新碟上架' },
                    component: () => import('../views/NewDiscPublish.vue')
                },

            ]
        },
        {
            path: '/b',
            meta: { title: '我的音乐' },
            component: () => import('../views/MyMusic.vue'),
            children: [
                {
                    path: 'myplaylist',
                    meta: { title: '我的歌单' },
                    component: () => import('../views/MyPlayList.vue')
                },
                {
                    path: 'mysinger',
                    meta: { title: '我的歌手' },
                    component: () => import('../views/MySinger.vue')
                },
                {
                    path: 'myradiostation',
                    meta: { title: '我的电台' },
                    component: () => import('../views/MyRadioStation.vue')
                },
            ]
        },
        {
            path: '/attention',
            meta: { title: '关注' },
            component: () => import('../views/Attention.vue')
        },
        {
            path: '/myinfo',
            meta: { title: '我的主页' },
            component: () => import('../views/MyInfo.vue')
        },
        {
            path: '/infoupdate',
            meta: { title: '个人设置' },
            component: () => import('../views/InfoUpdate.vue')
        },
        {
            path: '/creationcenter',
            meta: { title: '创作者中心' },
            component: () => import('../views/CreationCenter.vue')
        },
        {
            path: '/shopping',
            meta: { title: '商城' },
            component: () => import('../views/Shopping.vue')
        },
        {
            path: '/adsong',
            meta: { title: '云推歌' },
            component: () => import('../views/AdSong.vue')
        },
        {
            path: '/musician',
            meta: { title: '音乐人' },
            component: () => import('../views/Musician.vue')
        }, {
            path: '/download',
            meta: { title: '下载客户端' },
            component: () => import('../views/Download.vue')
        }
    ]
})

router.beforeEach((to, from, next) => {
    next()
})

router.afterEach((to, from) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    }
})

export default router